package com.zyq.validation.pojo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.*;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User2 {
    @NotNull(message = "用户名不能为null", groups = {User2.group1.class}) //SpringValidation框架提供的检测注解
    @NotBlank(message="名字不能为空" , groups = {User2.group1.class}) //SpringValidation框架提供的检测注解
    @Size(min=2,max=5,message = "名字字符过多(2到5个字符)" , groups = {User2.group1.class}) //SpringValidation框架提供的检测注解
    private String  userName;
    @Min(value = 0, message = "年龄不能小于0" , groups = {User2.group1.class}) //SpringValidation框架提供的检测注解
    @Max(value = 150,message = "年龄不能大于150" , groups = {User2.group1.class}) //SpringValidation框架提供的检测注解
    private int age;
    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$", message = "密码格式错误(6-16位)", groups = {User2.group2.class})
    private String pwd;
    @Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "手机号格式错误", groups = {User2.group2.class})
    private String phone;
    @Email(message = "邮箱格式错误", groups = {User2.group2.class}) //SpringValidation框架提供的检测注解
    private String email;

    @Past(message = "生日必须早于当前时间", groups = {User2.group2.class}) //SpringValidation框架提供的检测注解
    private Date birth;

    @PositiveOrZero(message = "余额必须大于等于0", groups = {User2.group2.class}) //SpringValidation框架提供的检测注解
    private Double money;

    public User2(String userName, String pwd) {
        this.userName = userName;
        this.pwd = pwd;
    }

    public interface  group1{}
    public interface  group2{}

}
